{include file="Public:header2"/}
<body style="min-height: 100%;background-color: #fff">

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form onsubmit="return false;">
                        <div class="layui-form" wid100 lay-filter="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">盒子名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" value="{$data['title']}" lay-verify="required" placeholder="盒子名称" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">是否首抽五折</label>
                                <div class="layui-input-inline" style="width: 700px">
                                    <input type="radio" name="is_shou_zhe" value="0" lay-filter="type" class="layui-input" title="否" {if $data.is_shou_zhe eq 0} checked {/if}>
                                    <input type="radio" name="is_shou_zhe" value="1" lay-filter="type" class="layui-input" title="是" {if $data.is_shou_zhe eq 1} checked {/if}>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">盒子封面图</label>
                                <div class="layui-input-inline">
                                    <input type="hidden" name="imgurl" value="{$data['imgurl']}" lay-verify="required" placeholder="请上传图片" autocomplete="off" class="layui-input" >
                                    <img  style="float:left;width:120px;" class="" id="imgurl" src="{:imageUrl($data['imgurl'])}">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">限购数量</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="max_num" value="{$data['max_num']}"  autocomplete="off" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">爬塔层级</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="floors_num" value="{$data['floors_num']}"  placeholder="请输入爬塔层数" autocomplete="off" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">开始时间</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="start_time" name="addtime" value="{$data['addtime']|date='Y-m-d H:i:s'}" class="layui-input" placeholder="开始时间" style="" autocomplete="off">
                                </div>      
                                <label class="layui-form-label">结束时间</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="end_time" name="end_time" value="{$data['end_time']|date='Y-m-d H:i:s'}" class="layui-input" placeholder="结束时间" style="" autocomplete="off">
                                </div>
                            </div>
                            <input type="hidden" name="id" value="{$data['id']}">
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" onclick="return check()">确认保存</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="Public:footer"/}
</body>
</html>
<script type="text/javascript">
    layui.use(['layer','form','upload','laydate'], function(){
        var $ = layui.$;
        var form = layui.form;
        var upload = layui.upload;

        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#start_time' //指定元素
            ,type : 'datetime'
            ,trigger : 'click'
        });
        laydate.render({
            elem: '#end_time' //指定元素
            ,type : 'datetime'
            ,trigger : 'click'
        });
        
        
        
        //执行实例
        upload.render({
            accept:'imgurl'
            ,elem: '#imgurl' //绑定元素
            ,url: '/admin/picture' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.status == 1){ //成功
                    layer.msg("上传成功",{icon:1,time:1000},function(){
                        $("#imgurl").attr("src",res.data.path);  //单图
                        $("input[name=imgurl]").val(res.data.imgurl);
                    });
                }else{ //失败
                    layer.msg(res.msg,{icon:2,anim:6,time:1500});
                }
            }
            ,error: function(){
                //请求异常回调
                layer.msg('服务繁忙，请稍后再试',{icon:2,anim:6,time:1500});
            }
        });
        
        
        
    });

    function check(){
        var url="{:url('/admin/climb_edit')}";
        var $ = layui.$;
        var load=layer.load(2);
        $.post(url,$("form").serialize(),function(data){
            if(data.status==1){
                layer.msg(data.msg,{icon:1,time:1500},function(){
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index);
                    parent.location.reload();
                });
            }else{
                layer.msg(data.msg,{icon:2,anim:6,time:1500},function(){
                    layer.close(load);
                });
            }
        })
    }
</script>
